package com.example.practice.controller;

import com.example.practice.entity.*;
import com.example.practice.service.FeekbackService;
import com.fasterxml.jackson.databind.util.JSONPObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.security.auth.message.callback.PrivateKeyCallback;
import java.util.List;

/**
 * (Feekback)表控制层
 *
 * @author makejava
 * @since 2023-12-21 15:52:59
 */
@RestController
@RequestMapping("/api/feekback")
@Api(tags = "FeelbackController")
public class FeekbackController {
    /**
     * 服务对象
     */
    @Resource
    private FeekbackService feekbackService;

    /**
     *通过uid查询
     */
    @ApiOperation("通过uid查询反馈")
    @GetMapping("/getByUid")
    public List<Feekback> getByUid(Integer uid) {
        List<Feekback> feekbacks = this.feekbackService.getByUid(uid);
        return feekbacks;
    }

    /**
     * 新增反馈
     */
    @ApiOperation("新增反馈")
    @RequestMapping("/addf")
    public JsonResponse addFeekback(@RequestBody Feekback feekback){
        int result = this.feekbackService.addFeekback(feekback);
        if (result==1) {
            return JsonResponse.success(result);
        }
        else {
            return JsonResponse.success(result);
        }
    }

    /**
     * 编辑数据
     *
     * @param feekback 实体
     * @return 编辑结果
     */
    @GetMapping("update")
    public Feekback update(Feekback feekback) {
        return this.feekbackService.update(feekback);
    }


    /**
     * 修改状态status
     */
    @GetMapping("/editStatus")
    public String editStatus(Integer id) {
        if(this.feekbackService.updateStatus(id) == 1) {
            return "成功";
        } else {
            return "失败";
        }
    }


    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.feekbackService.deleteById(id));
    }

    @GetMapping("/getFeekbackByUidPage")
    public respMsg getFeekbackByUidPage(Integer uid, pageMsg pageMsg){
        respMsg respMsg = this.feekbackService.queryAllByLimit(uid, pageMsg);
        return respMsg;
    }

    @GetMapping("/getFeekbackById")
    public Feekback getFeekbackById(Integer id){
        Feekback feekback = this.feekbackService.queryById(id);
        return feekback;
    }

    @GetMapping("/getAllByPage")
    public respMsg getAllByPage(pageMsg pageMsg) {
        respMsg respMsg = this.feekbackService.queryAll(pageMsg);
        return  respMsg;
    }

    @GetMapping("/searchStatus1")
    public respMsg searchStatus1(Integer status, pageMsg pageMsg) {
        respMsg respMsg = this.feekbackService.searchStatus1(status, pageMsg);
        return  respMsg;
    }

    @ApiOperation("学校端获取状态为0，1的全部反馈")
    @GetMapping("/getAllFeek")
    public List<Feekback> getAllFeek() {
        List<Feekback> feekbacks = this.feekbackService.getAllFeek();
        System.out.println(feekbacks);
        return feekbacks;
    }

    @ApiOperation("学校端获取指定反馈")
    @GetMapping("/getFeekback")
    public List<Feekback> getFeekback(String aname, String uname, Integer status) {
        List<Feekback> feekbacks = this.feekbackService.getFeekback(aname, uname, status);
        return feekbacks;
    }

    @ApiOperation("保存反馈文件")
    @PostMapping("/saveFeedUrl")
    public Integer saveFeedUrl(@RequestBody List<FeedUrl> feedUrl){return this.feekbackService.saveFeedUrl(feedUrl);}

    @ApiOperation("获取图片信息")
    @GetMapping("/selectFeedFile")
    public List<FeedUrl> selectFeedFile(Integer fid, Integer uid) {
        List<FeedUrl> urls = this.feekbackService.selectFeedFile(fid, uid);
        return urls;
    }

    @ApiOperation("通过uid获取所有反馈(学生老师端)")
    @GetMapping("/findAllFeedByUid")
    public List<Feekback> findAllFeedByUid(Integer uid) {
        List<Feekback> urls = this.feekbackService.findAllFeedByUid(uid);
        return urls;
    }

}

